//index.ts
import { createI18n } from 'vue-i18n'

interface Lang {
    lang: string | '',
    name: string | ''
  }

const modules = import.meta.globEager('./*')

function getLangAll(): any{
    let message:any = {}
    getLangFiles(modules,message)
    return message
}

export const lang:Lang[] = [
    {
      lang: "en_US",
      name: "English"
    },
    {
      lang: "zh_CN",
      name: "简体中文"
    },
  ]

export function getLangFiles(mList:any,msg:any){
    for(let path in mList){
    if(mList?.[path]?.default){
        let pathName  = path?.substring(path?.lastIndexOf('/') + 1,path?.lastIndexOf("."))

        if(msg[pathName]){
            msg[pathName] = {
                ...mList[pathName],
                ...mList[path].default
            }
        }else{
            msg[pathName] = mList[path].default
        }

    }
    }
}

const i18n = createI18n({
    legacy: false, // legacyMode
    globalInjection: true, // global register $t
    // default language
    locale: 'en_US',
    messages: getLangAll()
});
export default i18n;